//
//  NetWorkService.swift
//  cangchu
//
//  Created by kang on 2021/11/30.
//

import Foundation
import Alamofire

public protocol NetWorkCallBack{
    func onResult(status:Int,url:String)
}

public class NetWorkService{
    
    public static func getWebSocketUrl(callBack:((String)->Void)?){
        let url = "http://8.130.54.122:9999/api/open/getServer/" + PushConfig.meAppid! + "/" + PushConfig.meSecretKey!
        
        Alamofire.request(url, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON { result in
            
            Logger.log(message: "NetWorkService:\(result)")
            
            let json = result.result.value as! NSDictionary
            if json["code"] as! Int == 200{
                let webSocketUrl = json["data"] as! String
                callBack?(webSocketUrl)
            }else{
                callBack?("")
            }
        }
    }
}
